package org.nerve.webmagic;

import org.nerve.webmagic.bean.WebPage;
import org.nerve.webmagic.pool.DataPool;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.Map;

import static org.nerve.webmagic.bean.WebPage.*;

/**
 * org.nerve.webmagic
 * Created by zengxm on 2016/4/21 0021.
 */
public class CommonPipeline implements Pipeline {

	@Override
	public void process(ResultItems resultItems, Task task) {
		Map<String,Object> datas=resultItems.getAll();
		//解析成WebPage
		WebPage wp=new WebPage();
		wp.setDomain((String)datas.get(DOMAIN))
				.setHtml((String)datas.get(HTML))
				.setPickTime(System.currentTimeMillis())
				.setTitle((String)datas.get(TITLE))
				.setUrl((String)datas.get(URL))
				.setScreenShot((String)datas.get(SCREENSHOT))
				.setDriver((String)datas.get(DRIVER))
				;
		//加入dataPool
		DataPool.push(wp);
	}
}
